package main

import (
	"fmt"
	"strconv"
)

var md = []int{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

/**
使用分片的方式性能比split要高得多
*/
func dayOfYear(date string) int {
	var sum = 0
	//性能差
	//dateArray := strings.Split(date, "-")
	//year, _ := strconv.Atoi(dateArray[0])
	//month, _ := strconv.Atoi(dateArray[1])
	//day, _ := strconv.Atoi(dateArray[2])
	//性能好
	year, _ := strconv.Atoi(date[:4])
	month, _ := strconv.Atoi(date[5:7])
	day, _ := strconv.Atoi(date[8:])
	for i := 1; i < month; i++ {
		sum += md[i]
	}
	sum += day
	if month > 2 && ((year%4 == 0 && year%100 != 0) || year%400 == 0) {
		sum += 1
	}
	return sum
}

func main() {
	fmt.Println(dayOfYear("2003-03-01"))
	fmt.Println(dayOfYear("2004-03-01"))
}
